/*
 * ft6636.c
 *
 *  Created on: 2021年11月30日
 *      Author: master
 */
#include "fsl_pint.h"
#include "ft6636.h"
#include "iic.h"
#include "fsl_debug_console.h"

TP_STATUS TP_Status;
void Callback_TP_INT_Func(pint_pin_int_t pintr, uint32_t pmatch_status)
{
	uint8_t tp_points = 0;
	uint8_t buf[4] = {0};
	IIC_ReadByte(0x02, &tp_points);
	if(tp_points > 0 && !TP_Status.isPressed)
	{
		IIC_LenRead(NULL,FT6336_FT_TP1_REG,buf,4);
		TP_Status.isPressed = true;
		TP_Status.tp_x = ((uint16_t)(buf[0]&0X0F)<<8)+buf[1];
		TP_Status.tp_y = ((uint16_t)(buf[2]&0X0F)<<8)+buf[3];
		//PRINTF("PRESS_X:%d PRESS_Y:%d\r\n",TP_Status.tp_x,TP_Status.tp_y);
	}
}
void ft6636_init()
{
	uint8_t databuffer;
	SetSoftIIC_Config(IIC_FQ_400);
	IIC_ReadByte(FT6336_ID_G,&databuffer);
	IIC_WriteByte(FT6336_FT_DEVIDE_MODE, 0);
	IIC_WriteByte(FT6336_FT_ID_G_THGROUP, 22);
	IIC_ReadByte(FT6336_FT_ID_G_THGROUP, &databuffer);
	IIC_WriteByte(FT6336_FT_ID_G_PERIODACTIVE, 12);
}
